package com.bizdk.generator;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.awt.*;
import java.net.URI;
import java.util.StringJoiner;

@Slf4j
@MapperScan(basePackages = {"com.bizdk.**.mapper"})
@SpringBootApplication
public class GenApp implements ApplicationRunner {
    
    private @Value("${server.port:80}") Integer port;
    
    private @Value("${server.contextPath:}") String contextPath;
    
    public static void main(String[] args) {
        SpringApplication.run(GenApp.class, args);
        StringJoiner strJoi = new StringJoiner("\n");
        strJoi.add("=========================启动完成！！！===============================");
        System.out.println(strJoi.toString());
    }
    
    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.info("打开本地默认浏览器");
        StringBuilder strBu = new StringBuilder();
        strBu.append("cmd /c start ");
        strBu.append("http://localhost").append(":").append(port);
        if (StringUtils.isNotBlank(contextPath)) {
            strBu.append("/").append(contextPath);
        }
        try {
            Runtime.getRuntime().exec(strBu.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
